import { Component, OnInit } from '@angular/core';
import { Singlepage } from '../../model/singlepage';
import { Router, ActivatedRoute } from '@angular/router';
import { SinglepageService } from '../../service/singlepage.service';

@Component({
  selector: 'app-detailsinglepage',
  templateUrl: './detailsinglepage.component.html',
  styleUrls: ['./detailsinglepage.component.css']
})
export class DetailsinglepageComponent implements OnInit {
  sl:Array<Singlepage>;
  parm:string;
  singlepage:Singlepage;
 constructor(
   private router:Router,
 private routerinfo:ActivatedRoute,
 private singlepageservice:SinglepageService
 ) { 

   this.singlepage=new Singlepage();
 }

 ngOnInit() {
   this.parm=this.routerinfo.snapshot.params['id'];

     if(this.parm){
       this.getSinglepage(this.parm);
     }
     else{

       alert("参数异常，请刷新后重试");
       this.goBack();
     }
 }



 goBack(){
   this.router.navigate(['index']);
   }

  private getSinglepage(id:string){
     this.singlepageservice.getSinglepage(id)
     .then((data:Singlepage)=>{
      if(data){
     this.singlepage=data;
      }
      else{
        alert("参数异常，请刷新后重试");
      }
     })
   }
}
